package br.com.moto.web;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;

@ManagedBean(name = "loginController")
@SessionScoped
public class LoginMBean {

    private User user;
    
    public LoginMBean() {
    }
    
    public String getLoggedUser(){ 
        try{
            user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        }catch(Exception e){
            user = null;
        }
        
        if(user == null){
            return "";
        }
        return user.getUsername();
    }
      
    
}